<?	
	include_once("identificador.php");

	function insertCalendario($dbh, $calendario){
        $sql = "INSERT INTO Calendario (idCalendario, idAsignatura, nombre, enlace) VALUES (:idCalendario, :idAsignatura, :nombre, :enlace)";
        
        $stmt = $dbh->prepare($sql);
        
        $stmt->bindParam(':idCalendario', getId());
        $stmt->bindParam(':idAsignatura', $calendario->idAsignatura);
        $stmt->bindParam(':nombre', $calendario->nombre);
		$stmt->bindParam(':enlace', $calendario->enlace);
        
        $stmt->execute();
        
        return $stmt;
	}
	
	function deleteCalendario($dbh, $idCalendario){
		$sql = "DELETE FROM Calendario WHERE idCalendario = :idCalendario";
		$stmt = $dbh->prepare($sql);
        
        $stmt->bindParam(':idCalendario', $idCalendario);
        
        $stmt->execute();
        
        return $stmt;
	}
	
	function selectCalendario($dbh, $idCalendario){
        $sql = "SELECT * FROM Calendario WHERE idCalendario = :idCalendario";
        $stmt = $dbh->prepare($sql);
		
		$stmt->bindParam(':idCalendario', $idCalendario);
        
        $stmt->execute();
        $calendario = $stmt->fetch(PDO::FETCH_OBJ);
		$stmt->closeCursor();
		
        return $calendario;
	}
	
	function selectCalendariosByAsignatura($dbh, $idAsignatura){
		$sql = "SELECT * FROM Calendario WHERE idAsignatura = :idAsignatura";
        $stmt = $dbh->prepare($sql);
		
		$stmt->bindParam(':idAsignatura', $idAsignatura);
        
        $stmt->execute();
        $calendarios = $stmt->fetchALL(PDO::FETCH_OBJ);
		
        return $calendarios;
		
	}

?>